<template></template>

<script>
export default {
  name: "ChangeLang",
  computed: {
    /**
     * 切换中英文单个标题 chTitle 中文标题 enTitle 英文标题
     * @returns {function(*, *, *, *): *}
     */
    changeLangTitle() {
      const langed = this.$store.getters.langed;
      return (chTitle, enTitle) => {
        if (langed === "zhHans") {
          return chTitle;
        } else if (langed === "en") {
          return enTitle;
        }
      };
    },
    /**
     * 数组内title的中英文切换 items是要执行的数组，title，是默认引用字段，enTitle英文字段，chTitle是中文字段
     * @returns {function(*, *, *, *): *}
     */
    changeLang() {
      const langed = this.$store.getters.langed;
      return (items, title, enFiled, chFiled) => {
        items.forEach((item) => {
          if (item[enFiled] && langed === "en") {
            item[title] = item[enFiled];
          } else if (item[chFiled] && langed === "zhHans") {
            item[title] = item[chFiled];
          }
        });
        return items;
      };
    },
    t() {
      return (key) => {
        // const langed = this.$store.getters.langed;
        // const message = {
        //   en: require("../lang/en"),
        //   zhHans: require("../lang/zhHans"),
        // };
        return key;
        // const currentLang = message[langed]
        // return eval('currentLang.' + key)
      };
    },
  },
  methods: {},
};
</script>

<style scoped></style>
